<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/11 20:58:15 $)
// $RCSfile: teamwork.php,v $ : $Revision: 1.7 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

define("ENTRY_EVENT", 1);
define("ENTRY_TASK", 2);

define("ACTIVITY_CALL", 1);
define("ACTIVITY_APPOINTMENT", 2);

define("STATUS_TASK", 1);
define("STATUS_EVENT", 2);

define("PRIORITY_TASK", 1);

define("LABEL_TASK", 1);
define("LABEL_EVENT", 2);

define("CATEGORY_EVENT", 1);
define("CATEGORY_CONTACT", 2);

define("TEAMWORK_CONTACT", 1);
define("TEAMWORK_EVENT", 2);
define("TEAMWORK_TASK", 3);

define("LINK_CONTACT", TEAMWORK_CONTACT);
define("LINK_EVENT", TEAMWORK_EVENT);
define("LINK_TASK", TEAMWORK_TASK);

define("TASKVIEW_SIMPLE", "simple");
define("TASKVIEW_DETAILED", "detailed");
define("TASKVIEW_NEXTSEVENDAYS", "nextsevendays");
define("TASKVIEW_OVERDUE", "overdue");
define("TASKVIEW_BYASSIGNMENT", "assignment");
define("TASKVIEW_COMPLETED", "completed");

define("CONTACTVIEW_ADDRESSCARDS", "addresscards");
define("CONTACTVIEW_DETAILEDCARDS", "detailedcards");
define("CONTACTVIEW_DETAILLIST", "detaillist");
define("CONTACTVIEW_PHONELIST", "phonelist");
define("CONTACTVIEW_BYCOMPANY", "bycompany");

define("TASKLINK_CONTACT", 1);
define("TASKLINK_USER", 2);
define("TASKLINK_USERGROUP", 3);
define("TASKLINK_TICKET", 4);
define("TASKLINK_KNOWLEDGEBASE", 5);
define("TASKLINK_DOWNLOAD", 6);
define("TASKLINK_CHATHISTORY", 7);

define("TASKPRIORITY_LOW", 1);
define("TASKPRIORITY_MEDIUM", 2);
define("TASKPRIORITY_HIGH", 3);
define("TASKPRIORITY_URGENT", 4);

define("TASKSTATUS_NOTSTARTED", 1);
define("TASKSTATUS_INPROGRESS", 2);
define("TASKSTATUS_COMPLETED", 3);
define("TASKSTATUS_PENDINGINPUT", 4);
define("TASKSTATUS_DEFERRED", 5);
define("TASKSTATUS_PLANNED", 6);
define("TASKSTATUS_BOGUS", 7);

define("SYNCTYPE_SYNCML", 1);
define("SYNCTYPE_OUTLOOK", 2);

define("SYNCSTATUS_SUCCESS", 1);
define("SYNCSTATUS_FAILURE", 2);

/**
* Teamwork Module
*/
class teamwork {

	/**
	* Constructor to register any events, sections
	*/
	function teamwork() {
		global $_SWIFT, $events, $datastore;

		$events->registerEventModuleSWIFT(MODULE_TEAMWORK, $this);

		// ======= ADMIN CP =======
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "managestatus");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "managepriorities");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "managelabels");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "managecategories");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "insertstatus");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "editstatus");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "insertpriority");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "editpriority");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "insertlabel");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "editlabel");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "insertcategory");
		$events->registerEvent(EVENT_ADMIN, MODULE_TEAMWORK, "editcategory");

		// ======= SYNCWORKS =======
		$events->registerEvent(EVENT_SYNCWORKS, MODULE_TEAMWORK, "syncworks");
		$events->registerEvent(EVENT_SYNCWORKS, MODULE_TEAMWORK, "updateentries");

		// ======= CALLBACK =======
		$events->registerEvent(EVENT_CALLBACK, MODULE_TEAMWORK, "syncworkslogin");
		$events->registerEvent(EVENT_CALLBACK, MODULE_TEAMWORK, "syncworkslogout");

		// ======= STAFF CP =======
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "contacts");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "tasks");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "calendar");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "ajax");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "insertevent");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "editevent");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "inserttask");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "edittask");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "insertcontact");
		$events->registerEvent(EVENT_STAFF, MODULE_TEAMWORK, "editcontact");

		$eventaction = $events->eventdata["eventaction"];
		$datastore->cache("calendarstatuscache");
		$datastore->cache("calendarprioritycache");
		$datastore->cache("calendarlabelcache");
		$datastore->cache("calendarcategorycache");
		if ($eventaction == "syncworks")
		{
			$datastore->cache("syncworkscache");
		}
	}

	/**
	* Destructor, called to unregister any events etc
	*/
	function _teamwork() {
	}

	/*
	* Call back function
	*/
	function _eventcallback($eventtype, $eventaction)
	{
		global $_SWIFT, $interface, $template, $departments, $staffauth, $module, $grid, $xml, $staff, $settings, $dbCore, $events, $session, $loginshare, $cookie, $errormessage, $infomessage, $permissions, $mimelist, $datastore;

		if ($eventtype == EVENT_CALLBACK && ($eventaction == "syncworkslogin" || $eventaction == "syncworkslogout")) {
			require_once ("./modules/teamwork/syncworks_initexit.php");
			return true;
		} else if ($eventtype == EVENT_SYNCWORKS && ($eventaction == "syncworks" || $eventaction == "updateentries")) {
			require_once ("./modules/teamwork/syncworks_sync.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "calendar" || $eventaction == "insertevent" || $eventaction == "editevent")) {
			require_once ("./modules/teamwork/staff_calendar.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "tasks" || $eventaction == "inserttask" || $eventaction == "edittask")) {
			require_once ("./modules/teamwork/staff_tasks.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "contacts" || $eventaction == "insertcontact" || $eventaction == "editcontact")) {
			require_once ("./modules/teamwork/staff_contacts.php");
			return true;
		} else if ($eventtype == EVENT_STAFF && ($eventaction == "ajax")) {
			require_once ("./modules/teamwork/staff_ajax.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managestatus" || $eventaction == "insertstatus" || $eventaction == "editstatus")) {
			require_once ("./modules/teamwork/admin_status.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managepriorities" || $eventaction == "insertpriority" || $eventaction == "editpriority")) {
			require_once ("./modules/teamwork/admin_priorities.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managelabels" || $eventaction == "insertlabel" || $eventaction == "editlabel")) {
			require_once ("./modules/teamwork/admin_labels.php");
			return true;
		} else if ($eventtype == EVENT_ADMIN && ($eventaction == "managecategories" || $eventaction == "insertcategory" || $eventaction == "editcategory")) {
			require_once ("./modules/teamwork/admin_categories.php");
			return true;
		}

		return false;
	}
}
?>